
<template>
  <div class="order-list-container"
    ref="wrap">
    <el-breadcrumb separator="/">
      <el-breadcrumb-item >营销活动</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/index/activity' }">分销奖金比例配置</el-breadcrumb-item>
      <el-breadcrumb-item>{{activeData.typeName}}</el-breadcrumb-item>
    </el-breadcrumb>
    <div id="home-page">
      <el-form label-width="120px">
        <h1 style="padding-top:50px">活动配置</h1>
        <el-form-item label="活动名称：">
          <span>{{activeData.typeName}}</span>
        </el-form-item>
        <div v-if="activeData.type != 4">
          <el-form-item label="活动时间：">
            <div>
              <el-radio v-model="activeData.aging"
                :label="1">长期</el-radio>
              <div>
                <el-radio v-model="activeData.aging"
                  :label="2">
                  <el-date-picker v-model="startEndTime"
                    type="datetimerange"
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    style="padding: 0 15px;height:34px;"
                    value-format="yyyy-MM-dd HH:mm"
                    :editable="false"
                    :disabled="activeData.aging == 1">
                  </el-date-picker>
                </el-radio>
              </div>
            </div>
          </el-form-item>
          <div>
            <el-form-item v-if="activeData.type === 1">
              <h1>邀请人奖励</h1>
            </el-form-item>
            <el-form-item label="奖励次数："
              v-if="activeData.type === 1">
              <el-col :span="12">
                <span>奖励</span>&nbsp;&nbsp;
                <el-input style="width:200px"
                  v-model="activeData.num"
                  maxlength="3"></el-input> 次
                <span style="color:#999">（不填或0为无限制）</span>
              </el-col>
            </el-form-item>
            <el-form-item label="奖项设置：">
              <el-col :span="12">
                <span v-if="activeData.type === 3">订单金额的&nbsp;&nbsp;</span>
                <el-input style="width:200px"
                  v-model="activeData.prize"
                  maxlength="2"></el-input>
                <span v-if="activeData.type === 3">&nbsp;%</span>
                <span>好客币</span>
              </el-col>
            </el-form-item>
          </div>
        </div>
        <div v-if="activeData.type == 4">
          <el-form-item label="一级分成比例：">
            <el-input-number controls-position="right"
              v-model="activeData.num"
              :min="0"
              :max="100"></el-input-number>&nbsp;&nbsp;
            <span>%</span>
          </el-form-item>
          <el-form-item label="二级分成比例：">
            <el-input-number controls-position="right"
              v-model="activeData.prize"
              :min="0"
              :max="100"></el-input-number>&nbsp;&nbsp;
            <span>%</span>

          </el-form-item>
        </div>
      </el-form>

    </div>
    <div class="information-btns"
      :style="{width:width}">
      <el-button type="primary"
        size="small"
        @click="sure">保存</el-button>
      <el-button @click="back"
        size="small">取消</el-button>
    </div>
  </div>
</template>
<script>
import { getActivityDetail, saveActivity } from "@/public/js/active";
export default {
  components: {},
  props: {},
  data() {
    return {
      id: 0,
      type: "",
      timeType: "1",
      startEndTime: [],
      width: "",
      activeData: {},
      startTime: "",
      endTime: ""
    };
  },
  watch: {},
  computed: {},
  methods: {
    _getActivityDetail(id) {
      getActivityDetail({
        id: id
      }).then(res => {
        this.activeData = res.data.activeData;
        if (!this.activeData.startTime) {
          this.startEndTime = [];
        } else {
          this.startEndTime = [
            this.activeData.startTime,
            this.activeData.endTime
          ];
        }
      });
    },
    //保存
    sure() {
      if (
        this.activeData.aging == 2 &&
        (!this.startEndTime || !this.startEndTime.length)
      ) {
        this.$message.error("请输入活动持续时间");
        return false;
      } else if (!this.activeData.prize && this.activeData.prize != 0) {
        this.$message.error("请输入奖项设置");
      } else {
        saveActivity({
          id: this.id,
          aging: this.activeData.aging,
          startTime: this.activeData.aging == 2 ? this.startEndTime[0] : "",
          endTime: this.activeData.aging == 2 ? this.startEndTime[1] : "",
          num: this.activeData.num,
          prize: this.activeData.prize
        }).then(res => {
          console.log(res);
          if (!res.data.errCode) {
            this.$message({
              type: "success",
              message: "保存成功"
            });
            this.back();
          }
        });
      }
    },
    back() {
      this.$router.back();
    }
  },
  created() {
    this.id = this.$route.query.id;
    this._getActivityDetail(this.id);
    //设置默认活动时间
  },
  mounted() {
    this.width = this.$refs.wrap.offsetWidth + "px";
  }
};
</script>
<style lang="scss" scoped>
#home-page {
  font-size: 14px;
  padding: 0 30px;
  h1 {
    font-size: 16px;
    text-align: left;
    color: #6d2377;
    padding: 15px 0;
  }
  section {
    border-bottom: 1px solid #f6f6f6;
    .content {
      padding: 20px 0 10px 20px;
      .box {
        padding-bottom: 15px;
        label {
          margin-right: 25px;
          width: 80px;
          text-align: right;
          display: inline-block;
          font-weight: bold;
        }
        .renewTime {
          border: 1px solid #6d2377;
          padding: 8px;
          border-radius: 3px;
          margin-left: 10px;
        }
        .dayPrice {
          margin-right: 15px;
          border: 1px solid #6d2377;
          padding: 8px;
          border-radius: 3px;
        }
      }
    }
    &.account-info {
      .totlePrice {
        padding-top: 15px;
      }
    }
  }
}
.account-content {
  color: #000;
  width: 1000px;
  margin: 0 auto;
  .account-title {
    font-family: "MicrosoftJhengHei";
    font-size: 18px;
    text-align: center;
    padding-bottom: 12px;
  }
  .top-1 {
    line-height: 28px;
    border-bottom: 2px solid #000;
    padding-left: 10px;
    & > div {
      display: flex;
      & > span {
        flex: 1;
      }
    }
  }
  .list {
    text-indent: 30px;
    li {
      display: flex;
      & > span {
        flex: 1;
      }
      &.header {
        border-bottom: 2px solid #000;
      }
    }
  }
}
.goodsList-content {
  .el-table th {
    background: #fff !important;
  }
}
.information-btns {
  position: fixed;
  bottom: 0;
  box-sizing: border-box;
  padding: 10px;
  background: #fff;
  box-shadow: 0px -1px 4px rgba(0, 0, 0, 0.1);
}
</style>
